package code;

import java.util.HashMap;
import java.util.Map;

public class AllSwap {

	public static void main(String[] args) {
		String[] strings={"ax", "bx", "cx", "cy", "by", "ay", "aaa", "azz"};
		allSwap(strings);
		for(String s : strings){
			System.out.println(s);
		}
	}
	public static String[] allSwap(String[] strings) {
		  Map<String, Integer>map = new HashMap<String, Integer>();
		  for(int i=0; i<strings.length; i++){
		    String str=strings[i].substring(0,1);
		    if(map.containsKey(str)){
		      String tem;
		      tem=strings[i];
		      strings[i] = strings[map.get(str)];
		      strings[map.get(str)] = tem;
		      map.remove(str);
		      continue;
		    }
		    map.put(str,i);
		  }
		  return strings;
		}

}
